local Plugin = {}
Plugin.Title = "PermaMuter"
Plugin.Description = "Permanently mute players."
Plugin.Author = "Tom"
Plugin.ChatCommand = "permamute"
Plugin.Usage = "[players] [1/0]"
Plugin.Privileges = { "PermaMute" }

function Plugin:Call( ply, args )

if (!sql.TableExists( "permamuted_players" ) ) then
    local query = "CREATE TABLE permamuted_players ( steamID varchar(255), isMuted int )"
	permaresult = sql.Query(query)
end

if ( ply:EV_HasPrivilege( "PermaMute" )) then
local enabled = ( tonumber( args[ #args ] ) or 1 ) > 0
local players = evolve:FindPlayer( args, ply, true )

   for _, pl in ipairs( players ) do
			if ( enabled ) then
			    local aquery = "INSERT INTO permamuted_players VALUES ('"..pl:SteamID().."' , 1)"
	            sql.Query(aquery)
				evolve:Notify( evolve.colors.blue, ply:Nick(), evolve.colors.white, " has permanently muted ", evolve.colors.red, evolve:CreatePlayerList( players ), evolve.colors.white, "." )
				pl.EV_Muted = 1
			else
				local aquery = "DELETE FROM permamuted_players WHERE steamID = '"..pl:SteamID().."'"
	            sql.Query(aquery)
				evolve:Notify( evolve.colors.blue, ply:Nick(), evolve.colors.white, " has unpermamuted ", evolve.colors.red, evolve:CreatePlayerList( players ), evolve.colors.white, "." )
				pl.EV_Muted = 0
			end
		end
	end
end

timer.Create("permamute",1,0,function()
for _, pl in ipairs( player.GetAll() ) do
  local ID = sql.QueryValue( "SELECT isMuted from permamuted_players WHERE steamID = '"..pl:SteamID().."'" )
  if (ID) then
  pl.EV_Muted = 1
  end
end
end )


function Plugin:Menu( arg, players )
  if ( arg ) then
		table.insert( players, arg )
		RunConsoleCommand( "ev", "permamute", unpack( players ) )
  else
	return "Permanently Mute", evolve.category.punishment, { { "Enable", 1 }, { "Disable", 0 } }
	end
end

evolve:RegisterPlugin( Plugin )